package thread;

//sleep 模拟网络延时:放大问题的发生性，发现问题
public class TestSleep implements Runnable{
    private int ticket = 10;
    @Override
    public void run() {
        while(true){
            if(this.ticket <= 0){
                break;
            }

            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println(Thread.currentThread().getName() + "抢到了第"
                    + ticket-- + "张票");
        }
    }

    public static void main(String[] args) {
        TestSleep ticket = new TestSleep();

        new Thread(ticket,"x").start();
        new Thread(ticket,"y").start();
        new Thread(ticket,"z").start();
    }
}
